import request from '@/common/utils/request'
import {
	serv
} from '@/common/utils/config'
import loginConvert from './loginConvert'
import JsEncrypt from "@/common/utils/jsencrypt.min.js";
import {sm2} from 'sm-crypto';
//加密
export function encryptPwd(publicKey,pwd) {
  if (publicKey.publicKey) {
    if(publicKey.key.indexOf("rsa") != -1){
      let jsencrypt = new JsEncrypt();
      jsencrypt.setPublicKey(publicKey.publicKey);
      return jsencrypt.encrypt(pwd);
    }else{
      return "04"+sm2.doEncrypt(pwd, publicKey.publicKey, 1);
    }
  }
}
//取公钥
export function getPublicKey(data, username) {
	return request(serv.sysrest + '/api/encrypt/publicKey', {
		method: 'get',
		data: data,
		header: {
			opUser: username
		}
	});
}
//登录多租户检查
export function checkTenantNumBeforeLogin(data) {
	return request(serv.sysrest + '/api/user/checkTenantNumBeforeLogin',{
		method: 'get',
		data: data
	})
}
//多部门登录
export function afterCheckLogin(data) {
	return request(serv.sysrest + '/api/user/afterCheckLogin',{
		method: 'post',
		data: data
	})
}
//登录多部门检查
export function checkUserNumByMobileBeforeLogin(data) {
	return request(serv.sysrest + '/api/user/checkUserNumByMobileBeforeLogin',{
		method: 'post',
		data: data
	})
}
// 登录
export function Login(data) {
	return request(serv.sysrest + `/api/user/login`, {
		method: `post`,
		data: data
	})
}
//登录后获取用户等信息
export function qryUserDetails(data) {
	return new Promise((resolve, reject) => {
		let str = encodeURIComponent(JSON.stringify(data));
		request(serv.sysrest + "/api/user/qryUserRefDetail", {
			method: `get`,
			data: {
				data: str
			}
		}).then(res => {
			resolve(res);
		})
	})
}

//获取用户头像
export function qryUserById(data) {
	return request(serv.sysrest + '/api/basic/qryUserByUserId', {
		method: 'get',
		data: data
	})
}

// 获取积分规则
export function getIntegralRule(data) {
	return request(serv.config + '/api/conf/qryConfByItemCode', {
		method: 'get',
		data: data
	})
}

//获取积分兑换比例
export function getMoneyToIntegral(data){
	return request(serv.config + '/api/conf/qryConfByItemCode',{
		method: 'get',
		data: data
	})
}

// 获取用户浏览历史
export function getHistory(data) {
	return request(serv.order + '/api/goodsViewHistory/queryGoodsHistoryWithGoodsStatus', {
		method: 'get',
		data: data
	})
}
// 获取用户足迹历史
export function getfootHistory(data) {
	return request(serv.order + '/api/goodsViewLog/countHistoryGoods', {
		method: 'get',
		data: data
	})
}
// 获取密码规则
export function pwdStrategy(data) {
	return request(serv.sysrest + '/api/user/passwdStrategy', {
		method: 'get',
		data: data
	})
}

//验证手机号
export function h5ValidPhone(data) {
	return request(serv.sysrest + '/api/basic/h5ValidPhone',{
		method: 'get',
		data: data
	})
}
//短信验证码校验
export function h5CheckMsgCode(data) {
	return request(serv.sysrest + '/api/basic/h5CheckMsgCode',{
		method: 'post',
		data: data
	})
}

// 获取验证码
export function getCode(data) {
	return request(serv.sysrest + '/api/basic/sendValidMsgCode', {
		method: 'get',
		data: data
	})
}

// 修改密码
export function updatePwd(data) {
	return request(serv.sysrest + '/api/user/updatePasswd', {
		method: 'post',
		data: data
	})
}
// 验证码验证
export function validateCode(data) {
	return request(serv.sysrest + '/api/basic/validPhone', {
		method: 'post',
		data: data
	})
}
// 验证码验证
export function settings(data) {
	return request(serv.welfare + '/api/mobile/settings', {
		method: 'get',
		data: data
	})
}
// 公众号登录获取部门信息
export function getDeptInfoByKey(data) {
	return request(serv.sysrest + '/api/wxmp/getDeptInfo',{
		method: 'post',
		data: data
	})
}
// 公众号登录选择部门登录
export function deptToLogin(data) {
	return request(serv.sysrest + '/api/wxmp/deptToLogin', {
		method: 'post',
		data: data
	})
}
// 公众号绑定
export function wxBind(data) {
	return request(serv.sysrest + '/api/wxmp/bind', {
		method: 'post',
		data: data
	})
}
// 手机号绑定公众号信息
export function getMobileBindInfo(data) {
	return request(serv.sysrest + '/api/wxmp/getMobileBindInfo?mobile=' + data, {
		method: 'get'
	})
}
// serv.welfare + "/api/mobile/settings", {}
// 微信公众号绑定
export function wxmpPurchaseBinding(data) {
	return request(serv.sysrest + '/api/wxmp/purchaseBinding', {
		method: 'get',
		data:data
	})
}

// 微信公众号获取openid
export function wxmpGetOpenId(data) {
	return request(serv.sysrest + '/api/wxmp/getOpenId', {
		method: 'get',
		data:data
	})
}

// 单点登录
export function authLoginKey(data) {
	return request(serv.sysrest + '/api/user/authLoginKey', {
		method: 'get',
		data:data
	})
}

// 部门选泽
export function deptChoose(data) {
	return request(serv.sysrest + '/api/user/deptChoose', {
		method: 'get',
		data:data
	})
}

//短信登录验证手机号（短信防刷专用）
export function loginTelValidNew(data) {
	return request(serv.sysrest + '/api/basic/validateTel',{
		method: 'get',
		data: data
	})
}

export function sendLoginMsg(data) {
	return request(serv.sysrest + '/api/basic/sendLoginMsg',{
		method: 'get',
		data: data
	})
}

export function mobileLogin(data) {
	return request(serv.sysrest + '/api/user/mobileLogin',{
		method: 'post',
		data: data
	})
}

export function ztSsoLogin(data) {
	return request(serv.sysrest + '/api/ztet/ssoLogin',{
		method: 'get',
		data: data
	})
}
